import { ConfigEnv, defineConfig, loadEnv, UserConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from "path";
// https://vite.dev/config/
import { warppEnv } from "./src/utils/gloenv";
import viteCompression from "vite-plugin-compression";
export default defineConfig((mode:ConfigEnv):UserConfig=>{
  const env=loadEnv(mode.mode,process.cwd())
  const viteEnv=warppEnv(env)
  return{
    plugins: [
      react(),
      viteEnv.VITE_USE_COMPRESS && viteCompression({
        verbose: true,
        disable: false,
        threshold: 10240,
        algorithm: "gzip",
        ext: ".gz",
        filter: /\.(js|mjs|json|css|html)$/i,
      
      })
    ],
  resolve:{
    alias:{
      "@":resolve(__dirname,"src")
    }
  },
  server:{
    host:"0.0.0.0",
    port:viteEnv.VITE_PORT,
    open:viteEnv.VITE_OPEN,
    cors:true,
    proxy:{
      // [viteEnv.VITE_BASE_API]:{
      //   target:viteEnv.VITE_PROXY_TARGET,
      //   changeOrigin:true,
      //   rewrite:path=>path.replace(/^\/api/,'')
      // }
    }
  },
  build:{
    outDir:viteEnv.VITE_OUTPUT_DIR,
    rollupOptions:{
      output:{
        chunkFileNames:"assets/js/[name]-[hash].js",
        entryFileNames:"assets/js/[name]-[hash].js",
        assetFileNames:"assets/[name]-[hash].[ext]"
      }
    }

  }
  }
  
})
